home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Tools & Apps / OS⁄Toolbox / MDEF (LS Pascal) / UDPInstall.p < prev    next >
Encoding:
Text File  |  1990-08-13  |  1.8 KB  |  55 lines  |  [TEXT/PJMM]

  1. {Object Pascal Demonstration Program}
  2. {by Rich Siegel}
  3. {©1988 Symantec Corporation}
  4.  
  5. {This unit contains "InstallDefProc", which is a generic routine that makes it possible to have}
  6. {custom definition routines be installed as part of the program, rather than requiring the programmer}
  7. {to build and debug the code resources separately.}
  8.  
  9. {InstallDefProc does its thing by installing a "fake" defproc resource of the desired type and ID in}
  10. {the resource file designated by "dpPath". This resource contains a JMP instruction, followed by}
  11. {a destination for the JMP. If the resource doesn't exist, it's created and added to the file; if it's}
  12. {already in the desired file, it's simply loaded. Either way, the procedure's address (passed in}
  13. {"dpAddr") is set up in the handle, and the handle is made nonpurgeable.}
  14.  
  15. Unit UDPInstall;
  16. Interface
  17.     Procedure InstallDefProc (dpPath: Integer;
  18.                                     dpType: ResType;
  19.                                     dpID: Integer;
  20.                                     dpAddr: Ptr);
  21.  
  22. Implementation
  23.     Type
  24.         JmpRecord = Record
  25.                 jmpInstr: Integer;
  26.                 jmpAddr: Ptr;
  27.             End;
  28.         JmpPtr = ^JmpRecord;
  29.         JmpHandle = ^JmpPtr;
  30.  
  31.     Procedure InstallDefProc;
  32.         Var
  33.             jH: JmpHandle;
  34.  
  35.             savePath: Integer;
  36.  
  37.     Begin
  38.         savePath := CurResFile;        {preserve the resource file currently in use}
  39.         UseResFile(dpPath);                {look only in the specified path}
  40.  
  41.         jH := JmpHandle(GetResource(dpType, dpID)); {try to get the dummy defproc}
  42.  
  43.         If jH = Nil Then        {if it's not there, create a handle and add it.}
  44.             Begin
  45.                 jh := JmpHandle(NewHandle(SizeOf(JmpRecord)));
  46.                 AddResource(Handle(jh), dpType, dpID, '');
  47.             End;
  48.         jh^^.jmpInstr := $4EF9;            {Jump to absolute address}
  49.         jh^^.jmpAddr := dpAddr;        {the address to which we jump}
  50.  
  51.         HNoPurge(Handle(jH));            {make the defproc nonpurgeable}
  52.  
  53.         UseResFile(savePath);            {restore the resource file chain.}
  54.     End;
  55. End.